//////////////////////////////////////////////////////////////////////////
// This file defines common macros
#ifndef __COMMONDEF_H__
#define __COMMONDEF_H__

#define PI 3.14159265f
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define fix(a)		(((a) < 0 ) ? (int(ceil(a))) : (int(floor(a))))
#define fZero 0.000001

#define PARA_GET_INT(configfile,sectionname,valuename,dataname,buf)	\
	if(configfile.GetValue(sectionname,valuename,buf) == -1){ \
		cout << "ERROR! Failed to get " << valuename << " in section " << sectionname << "\n"; \
		return -1; } \
	else{dataname = atoi(buf);}

#define PARA_GET_FLOAT(configfile,sectionname,valuename,dataname,buf)	\
	if(configfile.GetValue(sectionname,valuename,buf) == -1){ \
		cout << "ERROR! Failed to get " << valuename << " in section " << sectionname << "\n"; \
		return -1; } \
	else{dataname = (float)atof(buf);}

#define PARA_GET_DOUBLE(configfile,sectionname,valuename,dataname,buf)	\
	if(configfile.GetValue(sectionname,valuename,buf) == -1){ \
		cout << "ERROR! Failed to get " << valuename << " in section " << sectionname << "\n"; \
		return -1; } \
	else{dataname = atof(buf);}

#define PARA_GET_STRING(configfile,sectionname,valuename,dataname,buf)	\
	if(configfile.GetValue(sectionname,valuename,buf) == -1){ \
		cout << "ERROR! Failed to get " << valuename << " in section " << sectionname << "\n"; \
		return -1; } \
	else{dataname = buf;}

#define PARA_GET_BOOL(configfile,sectionname,valuename,dataname,buf)	\
	if(configfile.GetValue(sectionname,valuename,buf) == -1){ \
		cout << "ERROR! Failed to get " << valuename << " in section " << sectionname << "\n"; \
		return -1; } \
	else{if(atoi(buf)==1){dataname=true;}else{dataname=false;}}

#define SAFE_DELETE(pPointer) if(pPointer){delete [] pPointer; pPointer=NULL;}

#include <string>
using namespace std;

# ifdef WIN32
	typedef __int64 fileoff;
	typedef fpos_t filepos;
# else
	typedef long long fileoff;
	typedef __off_t filepos; 
# endif


void StringReplace(string & dst, string src, string subsrc, string subdst);
inline int sgn(float x) {if(x==0)return 0;else if(x<0) return -1;else return 1;}
fileoff GetFileSize(string strFilename);
bool Confirm(string strMessage);

#define SAFETY_CHECK


#endif //__COMMONDEF_H__
